package com.padakeji.android.pworks.example.retrofit;

import android.os.Bundle;

import com.padakeji.android.pworks.app.PadaActivity;
import com.padakeji.android.pworks.example.R;
import com.padakeji.android.pworks.example.retrofit.api.TestApi;
import com.padakeji.android.pworks.example.retrofit.bean.TestBean;
import com.padakeji.android.pworks.ui.UIHelper;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
 * Created by AtanL on 2015/9/22.
 */
public class RetrofitTestActivity extends PadaActivity {

    private UIHelper uiHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrofit_test);

        uiHelper = new UIHelper(this);

        RestAdapter retrofit = new RestAdapter.Builder()
                .setEndpoint("http://192.168.199.153/padaweb/index.php")
                .build();

        TestApi api = retrofit.create(TestApi.class);
        api.getTest(2, new Callback<TestBean>() {
            @Override
            public void success(TestBean testBean, Response response) {
                uiHelper.showToast("Success " + testBean.d);
            }

            @Override
            public void failure(RetrofitError error) {
                uiHelper.showToast("Failure");
            }
        });

    }
}
